Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

unist-util-find-after

Package Overview
Dependencies
Maintainers
2
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unist-util-find-after

unist utility to find a node after another node

  • 4.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
527K
decreased by-32.77%
Maintainers
2
Weekly downloads
 
Created

What is unist-util-find-after?

The `unist-util-find-after` package is a utility for working with unist syntax trees. It allows you to find a node in a tree that comes after a given node, optionally matching a test function or type.

What are unist-util-find-after's main functionalities?

Find a node after a given node

This feature allows you to find the first node that comes after a given node in the tree. In this example, it finds the node that comes after the first paragraph.

const findAfter = require('unist-util-find-after');
const tree = { type: 'root', children: [
  { type: 'paragraph', children: [{ type: 'text', value: 'Hello' }] },
  { type: 'paragraph', children: [{ type: 'text', value: 'World' }] }
]};
const node = findAfter(tree, tree.children[0]);
console.log(node); // { type: 'paragraph', children: [{ type: 'text', value: 'World' }] }

Find a node after a given node matching a type

This feature allows you to find the first node of a specific type that comes after a given node. In this example, it finds the first heading node that comes after the first paragraph.

const findAfter = require('unist-util-find-after');
const tree = { type: 'root', children: [
  { type: 'paragraph', children: [{ type: 'text', value: 'Hello' }] },
  { type: 'heading', children: [{ type: 'text', value: 'Title' }] },
  { type: 'paragraph', children: [{ type: 'text', value: 'World' }] }
]};
const node = findAfter(tree, tree.children[0], 'heading');
console.log(node); // { type: 'heading', children: [{ type: 'text', value: 'Title' }] }

Find a node after a given node matching a test function

This feature allows you to find the first node that matches a test function and comes after a given node. In this example, it finds the paragraph node that contains the text 'World' after the first paragraph.

const findAfter = require('unist-util-find-after');
const tree = { type: 'root', children: [
  { type: 'paragraph', children: [{ type: 'text', value: 'Hello' }] },
  { type: 'heading', children: [{ type: 'text', value: 'Title' }] },
  { type: 'paragraph', children: [{ type: 'text', value: 'World' }] }
]};
const test = node => node.type === 'paragraph' && node.children[0].value === 'World';
const node = findAfter(tree, tree.children[0], test);
console.log(node); // { type: 'paragraph', children: [{ type: 'text', value: 'World' }] }

Other packages similar to unist-util-find-after

Keywords

FAQs

Package last updated on 24 Jan 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc